package com.gufe.mapper.user.community;

import com.gufe.entity.Post;
import com.gufe.vo.communityvo.PostVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PostMapper {

    // 获取所有帖子数据
    @Select("SELECT p.id, p.user_id, u.username, u.avatar, p.content, p.img_url, p.comment_count, p.created_at " +
            "FROM posts p LEFT JOIN users u ON p.user_id = u.id " +
            "ORDER BY p.created_at DESC")
    List<PostVO> getPosts();

    // 根据ID获取帖子详情信息
    @Select("SELECT p.id, p.user_id, p.content, p.img_url, p.comment_count, p.created_at, u.username, u.avatar " +
            "FROM posts p LEFT JOIN users u ON p.user_id = u.id WHERE p.id = #{id}")
    PostVO getPostById(Integer id);

    // 新建帖子
    @Insert("insert into posts (user_id, content, img_url) VALUES (#{userId},#{content},#{imgUrl})")
    void savePost(Post post);
}
